package com.mcflies.commons;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mcflies.bean.GroupListViewBean;
import com.mcflies.ui.R;

public class GroupListViewAdapter extends BaseAdapter {
	private Context context;
	private List<GroupListViewBean> list;
	private LayoutInflater inflater;

	public GroupListViewAdapter() {
	}

	public GroupListViewAdapter(Context context, List<GroupListViewBean> list) {
		this.context = context;
		this.list = list;
		inflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (null == view) {
			view = inflater
					.inflate(R.layout.android_group_list_view_item, null);
		}

		GroupListViewBean bean = list.get(position);
		LinearLayout groupListViewItemFlag_LL = (LinearLayout) view
				.findViewById(R.id.groupListViewItemFlag_LL);
		TextView groupListViewItemFlag_TV = (TextView) view
				.findViewById(R.id.groupListViewItemFlag_TV);

		LinearLayout groupListViewItemContent_LL = (LinearLayout) view
				.findViewById(R.id.groupListViewItemContent_LL);
		TextView groupListViewItemContent_TV = (TextView) view
				.findViewById(R.id.groupListViewItemContent_TV);
		if (bean.isFlag()) {
			groupListViewItemFlag_LL.setVisibility(View.VISIBLE);
			groupListViewItemContent_LL.setVisibility(View.GONE);
			groupListViewItemFlag_TV.setText(bean.getContent());
		} else {
			groupListViewItemFlag_LL.setVisibility(View.GONE);
			groupListViewItemContent_LL.setVisibility(View.VISIBLE);
			groupListViewItemContent_TV.setText(bean.getContent());
		}
		return view;
	}

	// 默认情况，如果这个方法不是分割符，返回true
	// 分隔符是无选中和无点击事件的
	// 说白了，你想不想把改position项当做分隔符，想的话就返回false，否则返回true
	@Override
	public boolean isEnabled(int position) {
		GroupListViewBean bean = list.get(position);
		if (bean.isFlag()) {
			return false;
		}
		return super.isEnabled(position);
	}

}
